<template>
 <lay-layout class="Pop">
  <lay-body>
   
   
    <lay-form :model="model" ref="layFormRef" class="MainForm" >


      <lay-form-item label="名称" prop="name" required>
        <lay-input v-model="model.name" placeholder=""></lay-input>
      </lay-form-item>

      <lay-form-item label="通讯地址" prop="endPoint" required>
        <lay-input v-model="model.endPoint" placeholder=""></lay-input>
      </lay-form-item>

      <lay-form-item label="备注" prop="memo" >
        <lay-textarea  v-model="model.memo" style=""></lay-textarea>

      </lay-form-item>



    </lay-form>

       
  </lay-body>

  <lay-footer>     
    <lay-button size="sm" type="primary" @click="toSubmit">保存</lay-button>
    <lay-button size="sm" @click="toCancel" style="margin-left:40px;">取消</lay-button>
  </lay-footer>
</lay-layout>

</template>

<script lang="ts">
import { ref, watch,reactive,onMounted,h } from 'vue'
import { layer } from '@layui/layer-vue'
import MyHttp from "../../library/MyHttp";  
import MyWin from "../../library/MyWin"; 
import MyPage from "../../library/MyPage"; 
import {MyExcel} from "../../library/MyExcel"; 
import {MySimpleExport,TableColumn} from "../../library/MySimpleExport"; 
import MyData from "../../library/MyData"; 
 

export default {
  props:{
      data:Object,
      isAdd:Boolean
  },

  setup(prop:any, context:any) {
    const baseUrl="/commdeal";
    const myWin=ref<any>(null);
    const model = reactive<any>(prop.data )
    const layFormRef = ref<any>()
    const toSubmit=async()=>{
      layFormRef.value.validate((isValidate:boolean, model:any, errors:Array<any>) => {
          if(!isValidate){
            let msg='';
            errors.forEach(element=>{ 
              msg+=`${element.message}
              `; 
            })
            
            MyWin.alert(msg,{});
            return;
          }
          save();
      });
    } 
    const toCancel=()=>{ 
      context.emit("cancel");  
      myWin.value.close();
    }
    const save=async()=>{
      let url=baseUrl+"/insert";
      if(!prop.isAdd){
        url=baseUrl+"/update";
      }
      var r=await new MyHttp().post(url,model,
        { 
        }
      ); 
      context.emit("ok",model); 
      myWin.value.close();  
    }

    const commTypeList=ref([
      {label:'TCP', value:'TCP'},
      {label:'UDP', value:'UDP'},
      {label:'HTTP', value:'HTTP' },
      {label:'MQTT', value:'MQTT' },
      {label:'WS', value:'MQTT' },
    ])
   
    onMounted(() =>{  
      myWin.value=new MyWin();
    });
    return {
      model,
      layFormRef,
      commTypeList,
      toSubmit,
      toCancel,

       

    }
  }
}
</script>
<style scoped>
.Pop .layui-footer,
.Pop .layui-header {
  height: 50px;
  text-align: center; 
  padding-top: 10px;
  
}  
.Pop .layui-body{
  padding-top: 10px;
  /* justify-content:start; */
   
}
.MainForm{
  margin: 10px;
  width:100%;
   
} 
  
 
</style>